package com.open.system.service.impl;

import com.open.system.mapper.UserNoticeMapper;
import com.open.common.model.Page;
import com.open.common.model.Sort;
import com.open.system.model.UserNotice;
import com.open.system.service.IUserNoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户通知关联
 *
 * @author 大树03
 * @date 2025-07-26 19:54
 */
@Service(value = "sysUserNoticeService")
@Slf4j
public class UserNoticeServiceImpl implements IUserNoticeService {

	private UserNoticeMapper userNoticeMapper;

    @Autowired
    public void setSysUserNoticeMapper(UserNoticeMapper userNoticeMapper) {
        this.userNoticeMapper = userNoticeMapper;
    }

    @Override
    @Transactional()
    public Boolean save(UserNotice model)  {
        return userNoticeMapper.save(model);
    }

    @Override
    @Transactional()
    public Boolean update(UserNotice model)  {
        return userNoticeMapper.update(model);
    }

	@Override
	public Page<UserNotice> findPage(Page<UserNotice> page, UserNotice item)  {
        Map<String,Object> map = new HashMap<String, Object>(4);
        int startPoint = (page.getIndex()-1)*page.getSize();
        map.put("orderBy",new Sort());
        map.put("item",item);
        map.put("startPoint",startPoint);
        map.put("endPoint",page.getSize());
        Integer count = userNoticeMapper.findPageCount(map);
        if (count > startPoint) {
            page.setItems(userNoticeMapper.findPage(map));
        }else {
            page.setItems(new ArrayList<UserNotice>());
        }
        page.setTotal(count);
        return page;
    }

	@Override
    public List<UserNotice> findByModel(UserNotice item)  {
        Map<String,Object> map=new HashMap<String, Object>(1);
        map.put("item",item);
        return userNoticeMapper.findByModel(map);
    }

	@Override
	public UserNotice findByPk(Long pk)  {
        return userNoticeMapper.findByPk(pk);
    }

    @Override
    public Integer countByModel(UserNotice item){
        Map<String,Object> map=new HashMap<String, Object>(1);
        map.put("item",item);
        return userNoticeMapper.findPageCount(map);
    }

    @Override
    @Transactional()
    public Boolean remove(List<Long> pks) {
        return userNoticeMapper.remove(pks) > 0;
    }

    @Override
    public Boolean removeByUserId(Long id) {
        return userNoticeMapper.removeByUserId(id) > 0;
    }

    @Override
    public Boolean batchSave(List<UserNotice> models) {
        return userNoticeMapper.batchSave(models);
    }

    @Override
    public Boolean batchUpdate(List<UserNotice> userNotices) {
        return userNoticeMapper.batchUpdate(userNotices);
    }
}